/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VisualizarPassagem.java
 *
 * Created on 27/06/2012, 21:18:12
 */
package skyuff;

import Controle.DAO;
import Controle.DataSource;
import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 * @author Máctassio
 */
public class VisualizarPassagem extends javax.swing.JFrame {    
    
    /** Creates new form VisualizarPassagem */
    public VisualizarPassagem() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        passagemLabel = new javax.swing.JLabel();
        vooLabel = new javax.swing.JLabel();
        vooTextField = new javax.swing.JTextField();
        classeLabel = new javax.swing.JLabel();
        classeTextField = new javax.swing.JTextField();
        assentoLabel = new javax.swing.JLabel();
        assentoTextField = new javax.swing.JTextField();
        precoLabel = new javax.swing.JLabel();
        precoTextField = new javax.swing.JTextField();
        cancelaRadioButton = new javax.swing.JRadioButton();
        confirmaButton = new javax.swing.JButton();
        cancelaButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(skyuff.SkyUFFApp.class).getContext().getResourceMap(VisualizarPassagem.class);
        passagemLabel.setText(resourceMap.getString("passagemLabel.text")); // NOI18N
        passagemLabel.setName("passagemLabel"); // NOI18N

        vooLabel.setText(resourceMap.getString("vooLabel.text")); // NOI18N
        vooLabel.setName("vooLabel"); // NOI18N

        vooTextField.setEditable(false);
        vooTextField.setText(resourceMap.getString("vooTextField.text")); // NOI18N
        vooTextField.setName("vooTextField"); // NOI18N

        classeLabel.setText(resourceMap.getString("classeLabel.text")); // NOI18N
        classeLabel.setName("classeLabel"); // NOI18N

        classeTextField.setEditable(false);
        classeTextField.setText(resourceMap.getString("classeTextField.text")); // NOI18N
        classeTextField.setName("classeTextField"); // NOI18N

        assentoLabel.setText(resourceMap.getString("assentoLabel.text")); // NOI18N
        assentoLabel.setName("assentoLabel"); // NOI18N

        assentoTextField.setEditable(false);
        assentoTextField.setText(resourceMap.getString("assentoTextField.text")); // NOI18N
        assentoTextField.setName("assentoTextField"); // NOI18N

        precoLabel.setText(resourceMap.getString("precoLabel.text")); // NOI18N
        precoLabel.setName("precoLabel"); // NOI18N

        precoTextField.setEditable(false);
        precoTextField.setText(resourceMap.getString("precoTextField.text")); // NOI18N
        precoTextField.setName("precoTextField"); // NOI18N
        precoTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                precoTextFieldActionPerformed(evt);
            }
        });

        cancelaRadioButton.setText(resourceMap.getString("cancelaRadioButton.text")); // NOI18N
        cancelaRadioButton.setName("cancelaRadioButton"); // NOI18N

        confirmaButton.setText(resourceMap.getString("confirmaButton.text")); // NOI18N
        confirmaButton.setName("confirmaButton"); // NOI18N
        confirmaButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                confirmaButtonMouseClicked(evt);
            }
        });

        cancelaButton2.setText(resourceMap.getString("cancelaButton2.text")); // NOI18N
        cancelaButton2.setName("cancelaButton2"); // NOI18N
        cancelaButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cancelaButton2MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(151, 151, 151)
                .addComponent(passagemLabel)
                .addContainerGap(201, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(assentoLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(assentoTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(classeLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(classeTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(vooLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(vooTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(precoLabel)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cancelaRadioButton)
                            .addComponent(precoTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE))))
                .addGap(100, 100, 100))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(confirmaButton)
                .addGap(112, 112, 112)
                .addComponent(cancelaButton2)
                .addContainerGap(128, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(passagemLabel)
                .addGap(42, 42, 42)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(vooTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(vooLabel))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(classeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(classeLabel))
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(assentoLabel, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(assentoTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(precoTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(precoLabel))
                .addGap(18, 18, 18)
                .addComponent(cancelaRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(confirmaButton)
                    .addComponent(cancelaButton2))
                .addGap(22, 22, 22))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void precoTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_precoTextFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_precoTextFieldActionPerformed

private void cancelaButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cancelaButton2MouseClicked
   this.dispose();
}//GEN-LAST:event_cancelaButton2MouseClicked

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        DAO dao = new DAO();
        ArrayList lista = new ArrayList();
        Modelo.Passagem passagem = new Modelo.Passagem();
        
        lista = (ArrayList) dao.carregarPassagens();
        
        Iterator i = lista.iterator();
        if(i.hasNext())
            do{
                passagem = (Modelo.Passagem) i.next();
                if(passagem.getCpfCliente().equals(DataSource.usuarioLogado.getCpf()))
                    break;
                else
                    passagem = null;
            } while(i.hasNext());
        if(passagem != null){
            vooTextField.setText(passagem.getNumeroVoo());
            classeTextField.setText(passagem.getClasse());
            assentoTextField.setText(passagem.getAssento());
            precoTextField.setText(Double.toString(passagem.getPreco()));
        }
    }//GEN-LAST:event_formWindowOpened

    private void confirmaButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_confirmaButtonMouseClicked
        this.dispose();
    }//GEN-LAST:event_confirmaButtonMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VisualizarPassagem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VisualizarPassagem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VisualizarPassagem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VisualizarPassagem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new VisualizarPassagem().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel assentoLabel;
    private javax.swing.JTextField assentoTextField;
    private javax.swing.JButton cancelaButton2;
    private javax.swing.JRadioButton cancelaRadioButton;
    private javax.swing.JLabel classeLabel;
    private javax.swing.JTextField classeTextField;
    private javax.swing.JButton confirmaButton;
    private javax.swing.JLabel passagemLabel;
    private javax.swing.JLabel precoLabel;
    private javax.swing.JTextField precoTextField;
    private javax.swing.JLabel vooLabel;
    private javax.swing.JTextField vooTextField;
    // End of variables declaration//GEN-END:variables
}
